TryUpdate Method

Task Parallel System.Threading

Compares the existing value for the specified key with a specified value, and if they’re equal, updates the key with a third value.

Namespace:  System.Collections.Concurrent
Assembly:  System.Threading (in System.Threading.dll)

Syntax

Visual Basic (Declaration)
Public Function TryUpdate ( _
	key As TKey, _
	newValue As TValue, _
	comparisonValue As TValue _
) As Boolean
C#
public bool TryUpdate(
	TKey key,
	TValue newValue,
	TValue comparisonValue
)

Parameters

key
Type: TKey
The key whose value is compared with comparisonValue and possibly replaced.
newValue
Type: TValue
The value that replaces the value of the element with key if the comparison results in equality.
comparisonValue
Type: TValue
The value that is compared to the value of the element with key.

Return Value

true if the value with key was equal to comparisonValue and replaced with newValue; otherwise, false.

Exceptions

ExceptionCondition
System..::.ArgumentNullExceptionkey is a null reference.

See Also